import {ELEMENT_TAG_ENUMS} from '../../enums/index'

export function findlineByNode(mainArr: Array<string>,currentNode:any|null):number{
   console.log("there is line")
   console.log(currentNode)
   const findRange = mainArr.filter(e=>e!="")
   return findRange.findIndex(e=>e==currentNode!.data)
}

export function findSpanInContainer(root:HTMLElement):any []{
    let complierArr = []
    const shouldRenderTextArr: HTMLCollection =root.children
    for(let i = 0;i<shouldRenderTextArr.length;i++){
        if(shouldRenderTextArr[i].tagName == ELEMENT_TAG_ENUMS.SPAN){
            complierArr.push(shouldRenderTextArr[i])
        }
    }
    return complierArr
}

export function setLabeledString(spanText:string,startIndex:number,endIndex:number):string{
    const fontString = spanText.substring(0,startIndex)
    const labelString = spanText.substring(startIndex,endIndex)
    const afterString =  spanText.substring(endIndex)
    return fontString+'<span style="background-color:red;color:white">'+labelString+'</span>'+afterString
}
